package com.tg.app.util;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import com.appbase.custom.config.ApiUrl;
import com.tange.core.backend.service.api.CoreApiUrl;
import com.tange.core.backend.service.ep.EnvironmentProxy;
import com.tg.app.activity.CloudServiceActivity;
import com.tg.app.activity.base.WebBaseActivity;
import com.tg.app.activity.device.DeviceSettingsActivity;
import com.tg.appcommon.android.TGToast;
import com.tg.data.bean.DeviceItem;
import com.tg.data.bean.DeviceSettingsInfo;
import com.appbase.custom.constant.CommonConstants;
import com.tange.base.toolkit.AppUtil;
import com.tange.base.toolkit.PreferenceUtil;

import static com.tg.app.activity.device.DeviceSettingsActivity.EXT_DEVICE_INFO;

public class UriUtil {
    public static String getCurLocationUrl(Context context, final DeviceItem deviceItem){
        String url = "";
        if (deviceItem != null){
            EnvironmentProxy.initStatic();
            String token = PreferenceUtil.getString(context, CommonConstants.PRE_TOKEN);
            String param = String.format("platform=android&version=%s&token=%s", AppUtil.getVersionName(context),token);
            url = String.format("%s%s?%s&uuid=%s", CoreApiUrl.TG_STATIC, ApiUrl.DRIVE_LOCATION, param,deviceItem.uuid);
        }
        return url;
    }

    public static void openServePlayImpl(Activity activity, Intent intent, String url, String title, int type) {
//        intent.putExtra(WebBaseActivity.KEY_WEBURL, url);
//        intent.putExtra(WebBaseActivity.KEY_WEBTITLE, title);
//        intent.putExtra(CloudServiceActivity.EXT_CLOUD_SERVICE_TYPE, type);
//        intent.setClass(activity, CloudServiceActivity.class);
//        activity.startActivityForResult(intent, 0);

        TGToast.showToast("该功能暂未开放");
    }

    public static void openServePlay(Activity activity, String url, long deviceId, int type,  int requestCode){
        Intent intent = new Intent(activity, CloudServiceActivity.class);
        DeviceSettingsInfo info = new DeviceSettingsInfo();
        info.deviceID = deviceId;
        intent.putExtra(WebBaseActivity.KEY_WEBURL, url);
        intent.putExtra(DeviceSettingsActivity.EXT_DEVICE_INFO, info);
        intent.putExtra(CloudServiceActivity.EXT_CLOUD_SERVICE_TYPE, type);
        activity.startActivityForResult(intent, requestCode);
    }
    public static void openServePlay(Activity activity, String url, DeviceSettingsInfo info, int type){
        Intent intent = new Intent(activity, CloudServiceActivity.class);
        intent.putExtra(WebBaseActivity.KEY_WEBURL, url);
        intent.putExtra(DeviceSettingsActivity.EXT_DEVICE_INFO, info);
        intent.putExtra(CloudServiceActivity.EXT_CLOUD_SERVICE_TYPE, type);
        activity.startActivityForResult(intent, 0);
    }

    public static void openCarServePlay(Activity activity, Intent intent, String title){
        openServePlayImpl(activity, intent, ApiUrl.CAR_DETAIL_PAGE, title, 0);
    }

    public static void openCarServePlayEx(Activity activity, String title, long deviceId){
        Intent intent = new Intent();
        DeviceSettingsInfo info = new DeviceSettingsInfo();
        info.deviceID = deviceId;
        intent.putExtra(EXT_DEVICE_INFO, info);
        intent.setClass(activity.getBaseContext(), CloudServiceActivity.class);
        openServePlayImpl(activity, intent, ApiUrl.CAR_DETAIL_PAGE, title, 0);
    }
}
